package com.ysqcould.content.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysqcould.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ysqcould.content.mapper.AdvertisingMapper;
import com.ysqcould.content.domain.Advertising;
import com.ysqcould.content.service.IAdvertisingService;

/**
 * 广告Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-29
 */
@Service
public class AdvertisingServiceImpl extends ServiceImpl<AdvertisingMapper,Advertising> implements IAdvertisingService
{
    @Autowired
    private AdvertisingMapper advertisingMapper;

    /**
     * 查询广告
     * 
     * @param id 广告主键
     * @return 广告
     */
    @Override
    public Advertising selectAdvertisingById(Long id)
    {
        return advertisingMapper.selectAdvertisingById(id);
    }

    /**
     * 查询广告列表
     * 
     * @param advertising 广告
     * @return 广告
     */
    @Override
    public List<Advertising> selectAdvertisingList(Advertising advertising)
    {
        List<Advertising> list = advertisingMapper.selectAdvertisingList(advertising);
        list.stream().filter(p->p.getPressType()!=null).forEach(p->{
            String[] split = p.getPressType().split(";");
            p.setPressTypeList(split);
        });
        return list;
    }

    /**
     * 新增广告
     * 
     * @param advertising 广告
     * @return 结果
     */
    @Override
    public int insertAdvertising(Advertising advertising)
    {
        advertising.setCreateTime(DateUtils.getNowDate());
        return advertisingMapper.insertAdvertising(advertising);
    }

    /**
     * 修改广告
     * 
     * @param advertising 广告
     * @return 结果
     */
    @Override
    public int updateAdvertising(Advertising advertising)
    {
        advertising.setUpdateTime(DateUtils.getNowDate());
        return advertisingMapper.updateAdvertising(advertising);
    }

    /**
     * 批量删除广告
     * 
     * @param ids 需要删除的广告主键
     * @return 结果
     */
    @Override
    public int deleteAdvertisingByIds(Long[] ids)
    {
        return advertisingMapper.deleteAdvertisingByIds(ids);
    }

    /**
     * 删除广告信息
     * 
     * @param id 广告主键
     * @return 结果
     */
    @Override
    public int deleteAdvertisingById(Long id)
    {
        return advertisingMapper.deleteAdvertisingById(id);
    }

    @Override
    public int updateStatus(Advertising advertising) {
        Advertising adv = advertisingMapper.selectAdvertisingById(advertising.getId());
        adv.setStatus(2);
        return advertisingMapper.updateAdvertising(adv);
    }
}
